import Vue from "vue";
import Router from "vue-router";
import { loginAuth } from "../../../../util/auth";
import axios from "axios";

Vue.use(Router);

const router = new Router({ 
  mode: "hash",
  routes: [
    {
      path: "/",
      redirect: {
        path: "/index",
      },
    },
    {
      path: "/index",
      name: "主页面",
      component: (resolve) => {
        require(["../views/index.vue"], resolve);
      },
      children: [
        {
          path: "",
          redirect: "project",
        },
        {
          path: "home",
          name: "首页",
          component: (resolve) => {
            require(["../views/home.vue"], resolve);
          },
        },
        {
          path: "project",
          name: "项目",
          component: (resolve) => {
            require(["../views/project.vue"], resolve);
          },
        },
        {
          path: "material",
          name: "素材管理",
          component: (resolve) => {
            require(["../views/material.vue"], resolve);
          },
          children: [
            {
              path: "",
              redirect: "picture",
            },
            {
              path: "picture",
              name: "图片",
              component: (resolve) => {
                require(["../views/material/picture.vue"], resolve);
              },
            },
          ],
        },
      ],
    },
  ],
});
router.beforeEach((to, from, next) => {
  // 登录验证，开发环境请注释
  // if (process.env.NODE_ENV === "production") {
  loginAuth();
  // }
  next();
});

router.afterEach((to, from, next) => {
  document.title = to.name;
});

export default router;
